package pri.hillchen.springbootstd.sso.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pri.hillchen.springbootstd.sso.common.base.BaseController;
import pri.hillchen.springbootstd.sso.common.response.ListResponse;
import pri.hillchen.springbootstd.sso.entity.MenuInfo;
import pri.hillchen.springbootstd.sso.service.MenuService;
import pri.hillchen.springbootstd.sso.util.SpringMvcRequestUtil;

/**
 * @author:hillchen
 * @DESCRIPTION:
 * @Date: Created in 9:23 2017/12/13 0013.
 */
@Controller
public class SystemController extends BaseController{
    @Autowired
    private MenuService menuService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/getMenus")
    @ResponseBody
    public ListResponse<MenuInfo> getMenus(){

        String token = SpringMvcRequestUtil.getCurrentToken();
        String systemCode = SpringMvcRequestUtil.getCurrentRequestSys();

        if(StringUtils.hasText(token) && token.equals(stringRedisTemplate.opsForValue().get("token:"+token))){
            ListResponse<MenuInfo> response = new ListResponse<>();
            response.setReqResult(menuService.getPrivilegeMenus(token,systemCode));
            return response;
        }else{
            return ListResponse.createEmptyResponse();
        }

    }
}
